package com.example.keli.ui.reward;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.keli.R;
import com.example.keli.base.BaseActivity;
import com.example.keli.base.utils.DataUtil;
import com.example.keli.base.utils.GlideUtil;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;

public class RewardDetailsActivity extends BaseActivity {


    private static final String TAG = "RewardDetailsActivity";
    @BindView(R.id.iv_reward_details)
    ImageView ivRewardDetails;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_status)
    TextView tvStatus;
    @BindView(R.id.tv_num)
    TextView tvNum;
    @BindView(R.id.tv_date)
    TextView tvDate;
    @BindView(R.id.tv_introduce)
    TextView tvIntroduce;
    @BindView(R.id.recycler_reward_rank)
    RecyclerView recyclerRewardRank;
    @BindView(R.id.recycler_reward_list)
    RecyclerView recyclerRewardList;
    private RewardList.RewardVO mRewardVO;
    private RewardRankAdapter rewardRankAdapter;
    protected final List<String> sStatus = Arrays.asList("待启动", "报名中","进行中","已结束");
    private List<RewardRank> ranks;
    private List<RewardList.RewardVO.RewardUserBean.DataBean> rewardUserBeans;

    @Override
    protected int layoutId() {
        return R.layout.activity_reward_details;
    }

    @Override
    protected void bindData() {
//        setTitle("奖品详情");
        abTitle.setText("奖品详情");
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mRewardVO = (RewardList.RewardVO) getIntent().getSerializableExtra("reward");
        if (mRewardVO != null) {
//            Glide.with(this).load(mRewardVO.getCover_picture()).into(ivRewardDetails);
            GlideUtil.displayRound(this, ivRewardDetails, mRewardVO.getCover_picture(), 5);
            tvName.setText(mRewardVO.getTitle());
            tvStatus.setText(sStatus.get(mRewardVO.getStatus()-1));
            tvNum.setText("参与人数:  "+String.valueOf(mRewardVO.getEnrollCount())+"人");
            tvDate.setText("起止时间:  "+DataUtil.getData(mRewardVO.getStart_time())+"-"+DataUtil.getData(mRewardVO.getEnd_time()));
            tvIntroduce.setText(mRewardVO.getContent());
            initRewardRankRecycle();
            initRewardListRecycle();
        }
    }

    private void initRewardListRecycle() {
        rewardUserBeans = new ArrayList<>();
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerRewardList.setLayoutManager(linearLayoutManager);
    }

    private void initRewardRankRecycle() {
        ranks = new ArrayList<>();
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerRewardRank.setLayoutManager(linearLayoutManager);
        recyclerRewardRank.setNestedScrollingEnabled(false);
        Log.e(TAG, "initRewardRankRecycle: "+mRewardVO.getReward_one_content());
        if (!TextUtils.isEmpty(mRewardVO.getReward_one_content())){
            RewardRank rank = new RewardRank();
            rank.setTitle(mRewardVO.getReward_one_title());
            rank.setImg(mRewardVO.getReward_one_img());
            rank.setContent(mRewardVO.getReward_one_content());
            ranks.add(rank);
        }
        if (!TextUtils.isEmpty(mRewardVO.getReward_two_content())){
            RewardRank rank = new RewardRank();
            rank.setTitle(mRewardVO.getReward_two_title());
            rank.setImg(mRewardVO.getReward_two_img());
            rank.setContent(mRewardVO.getReward_two_content());
            ranks.add(rank);
        }
        if (!TextUtils.isEmpty(mRewardVO.getReward_three_content())){
            RewardRank rank = new RewardRank();
            rank.setTitle(mRewardVO.getReward_three_title());
            rank.setImg(mRewardVO.getReward_three_img());
            rank.setContent(mRewardVO.getReward_three_content());
            ranks.add(rank);
        }
        if (!TextUtils.isEmpty(mRewardVO.getReward_four_content())){
            RewardRank rank = new RewardRank();
            rank.setTitle(mRewardVO.getReward_four_title());
            rank.setImg(mRewardVO.getReward_four_img());
            rank.setContent(mRewardVO.getReward_four_content());
            ranks.add(rank);
        }
        rewardRankAdapter = new RewardRankAdapter(this, R.layout.item_reward_rank, ranks);
        recyclerRewardRank.setAdapter(rewardRankAdapter);
    }



    public static class RewardRank {
        //冠军  亚军 季军
        private String title;
        private String img;
        private String content;

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public String getImg() {
            return img;
        }

        public void setImg(String img) {
            this.img = img;
        }

        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }
    }

}
